package com.tpp.controller;

import com.tpp.pojo.baseVo.BaseResult;
import com.tpp.pojo.req.TppUserReq;
import com.tpp.service.UserService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Base64;
import java.util.Map;

@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 邮箱的检验
     * @param email
     * @return
     */
    @GetMapping(value = "/validataEmail")
    public BaseResult validataEmail(@RequestParam("email")String email){
        return userService.validataEmail(email);
    }
    @GetMapping("/validataPhone")
    public BaseResult validataPhone(@RequestParam("phone")String phone){
        return userService.validataPhone(phone);
    }

    /**
     * 注册时，用户名的检验
     * @param map
     * @return
     */
    @PostMapping("/validataloginName")
    public BaseResult validataloginName(@RequestBody Map map){
        return userService.validataloginName(map);
    }

    /**
     * 获取邮箱验证码
     * @param email
     * @return
     */
    @GetMapping("/getCode")
    public BaseResult getCode(@RequestParam("email")String email){
        return userService.sendMail(email);
    }

    @GetMapping("/getInCode")
    public BaseResult getInCode(@RequestParam("phone")String phone){
        return userService.sendInformation(phone);
    }

    /**
     * 邮箱注册
     * @param tppUserReq
     * @return
     */
    @PostMapping( "/registry")
    public BaseResult registry(@RequestBody TppUserReq tppUserReq){
        return userService.registry(tppUserReq);
    }

    /**
     * 登录
     * @param tbUserReq
     * @return
     */
    @PostMapping("/login")
    public BaseResult login(@RequestBody TppUserReq tbUserReq){
        return userService.login(tbUserReq);
    }

    /**
     * 从token获取tppuser
     * @param request
     * @return
     */
    @PostMapping("/findUserByToken")
    public BaseResult findUserByToken(HttpServletRequest request){
        return userService.findUserByToken(request);
    }

    /**
     * 退出登陆
     * @param request
     * @return
     */
    @PostMapping("/loginOut")
    public BaseResult loginOut(HttpServletRequest request){
        return userService.loginOut(request);
    }

    /**
     * 修改个人信息
     * @param tppUserReq
     * @param request
     * @return
     */
    @PostMapping("/updateUser")
    public BaseResult updateUser(@RequestBody TppUserReq tppUserReq, HttpServletRequest request){
        return userService.updateUser(tppUserReq,request);
    }

    /**
     * 在记得密码的情况下，修改密码
     * @param tppUserReq
     * @param request
     * @return
     */
    @PostMapping("/updatePassword1")
    public BaseResult updatePassword(@RequestBody TppUserReq tppUserReq,HttpServletRequest request){
        return userService.updatePassword(tppUserReq,request);
    }

    /**
     * 忘记密码时，使用邮箱验证身份
     * @param tppUserReq
     * @return
     */
    @PostMapping("/verigyMail")
    public  BaseResult verigyMail(@RequestBody TppUserReq tppUserReq){
        return userService.verigyMail(tppUserReq);
    }

    /**
     * 忘记密码时，使用手机号验证身份
     * @param tppUserReq
     * @return
     */
    @PostMapping("/verigyPhone")
    public  BaseResult verigyPhone(@RequestBody TppUserReq tppUserReq){
        return userService.verigyPhone(tppUserReq);
    }

    @PostMapping("/updatePassword2")
    public BaseResult updatePassword2(@RequestBody TppUserReq tppUserReq){
        return userService.updatePassword2(tppUserReq);
    }






    /**
     * 上传图片
     * @param multipartFile
     * @return
     */
    @RequestMapping("/upload")
    public BaseResult uploadImg(@RequestParam("file") MultipartFile multipartFile){

        return userService.upload(multipartFile);
    }




}
